package cn.tianyun.pethome.basic.util;

import cn.tianyun.pethome.shop.domain.ShopAo;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;


import javax.mail.internet.MimeMessage;
import java.io.File;

@Component
public class EmailUtil {

    @Autowired
    private JavaMailSender javaMailSender;


    public void  send(){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置发送人
        mailMessage.setFrom("1498380330@qq.com");
        //邮件主题
        mailMessage.setSubject("ghaefuieahfuisdff");
        //邮件内容
        mailMessage.setText("发的v额为啊发射点十分士大夫但是二十.....");
        //收件人
        mailMessage.setTo("1498380330@qq.com");

        javaMailSender.send(mailMessage);
    }

    public void send2(ShopAo shopAo) throws Exception{
        //创建复杂邮件对象
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        //发送复杂邮件的工具类
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
        helper.setFrom("1498380330@qq.com");
        helper.setSubject("店铺审核");//邮件标题
        //第二个参数 true 代表是否是一个html内容
        helper.setText("<h1>审核成功</h1><br>"+
                "<span>成功原因："+shopAo.getNote()+"</span><br>"+
                "<a href='http://127.0.0.1:8080/shop/active/"+shopAo.getId()+"'>点击激活</a>",true);
        //添加附件
        /*helper.addAttachment("文件名.jpg",new File("D:\\田云\\Pictures\\Saved Pictures\\1.jpg"));
        helper.addAttachment("压缩文件", new File("D:\\田云\\Pictures\\Saved Pictures\\1.zip"));*/
        //收件人
        helper.setTo("1498380330@qq.com");
        //发送邮件
        javaMailSender.send(mimeMessage);
    }
}